﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;

namespace CAD.DAO
{
    public class DAOActivos
    {
    
        public int Insertar(string ICODIGOBARRAS, string SDESCIPCION_DSC, string SPROPIEDAD, DateTime DTFECHADECOMPRA_DT, DateTime DTFECHADEALTA_DT, int IVIDAUTIL, string SESTADO, string SMARCA, string SMODELO, string SFORMA, string SSERIAL, string SCOLOR, string SCAPACIDAD, string SMATERIAL, string SALTO, string SLARGO, string SANCHO, int IDIAMETRO, int INUMERODEDIVICIONES, string STIPOASIGNACION, string STIPODEALTA, int INUMEROCOMPROBANTE, string SREPORTADOALSEGURO, double IVALOR, int ICONCURRENCIA, int LFAMILIAS_ID, int LPROVEEDOR_ID, int LPERSONAL_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LACTIVOS_ID";
            prmA.Direction = ParameterDirection.Output;
            lstParametros.Add(prmA);

            DbParameter prmB = new SqlParameter();
            prmB.DbType = DbType.String;
            prmB.ParameterName = "@ICODIGOBARRAS";
            prmB.Value = ICODIGOBARRAS;
            prmB.Direction = ParameterDirection.Input;
            lstParametros.Add(prmB);

            DbParameter prmC = new SqlParameter();
            prmC.DbType = DbType.String;
            prmC.ParameterName = "@SDESCIPCION_DSC";
            prmC.Value = SDESCIPCION_DSC;
            prmC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmC);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.String;
            prmD.ParameterName = "@SPROPIEDAD";
            prmD.Value = SPROPIEDAD;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);

            DbParameter prmE = new SqlParameter();
            prmE.DbType = DbType.DateTime;
            prmE.ParameterName = "@DTFECHADECOMPRA_DT";
            prmE.Value = DTFECHADECOMPRA_DT;
            prmE.Direction = ParameterDirection.Input;
            lstParametros.Add(prmE);

            DbParameter prmF = new SqlParameter();
            prmF.DbType = DbType.DateTime;
            prmF.ParameterName = "@DTFECHADEALTA_DT";
            prmF.Value = DTFECHADEALTA_DT;
            prmF.Direction = ParameterDirection.Input;
            lstParametros.Add(prmF);

            DbParameter prmG = new SqlParameter();
            prmG.DbType = DbType.Int32;
            prmG.ParameterName = "@IVIDAUTIL";
            prmG.Value = 8;
            prmG.Direction = ParameterDirection.Input;
            lstParametros.Add(prmG);

            DbParameter prmH = new SqlParameter();
            prmH.DbType = DbType.String;
            prmH.ParameterName = "@SESTADO";
            prmH.Value = SESTADO;
            prmH.Direction = ParameterDirection.Input;
            lstParametros.Add(prmH);

            DbParameter prmI = new SqlParameter();
            prmI.DbType = DbType.String;
            prmI.ParameterName = "@SMARCA";
            prmI.Value = SMARCA;
            prmI.Direction = ParameterDirection.Input;
            lstParametros.Add(prmI);

            DbParameter prmJ = new SqlParameter();
            prmJ.DbType = DbType.String;
            prmJ.ParameterName = "@SMODELO";
            prmJ.Value = SMODELO;
            prmJ.Direction = ParameterDirection.Input;
            lstParametros.Add(prmJ);

            DbParameter prmK = new SqlParameter();
            prmK.DbType = DbType.String;
            prmK.ParameterName = "@SFORMA";
            prmK.Value = SFORMA;
            prmK.Direction = ParameterDirection.Input;
            lstParametros.Add(prmK);

            DbParameter prmL = new SqlParameter();
            prmL.DbType = DbType.String;
            prmL.ParameterName = "@SSERIAL";
            prmL.Value = SSERIAL;
            prmL.Direction = ParameterDirection.Input;
            lstParametros.Add(prmL);

            DbParameter prmM = new SqlParameter();
            prmM.DbType = DbType.String;
            prmM.ParameterName = "@SCOLOR";
            prmM.Value = SCOLOR;
            prmM.Direction = ParameterDirection.Input;
            lstParametros.Add(prmM);

            DbParameter prmN = new SqlParameter();
            prmN.DbType = DbType.String;
            prmN.ParameterName = "@SCAPACIDAD";
            prmN.Value = SCAPACIDAD;
            prmN.Direction = ParameterDirection.Input;
            lstParametros.Add(prmN);

            DbParameter prmO = new SqlParameter();
            prmO.DbType = DbType.String;
            prmO.ParameterName = "@SMATERIAL";
            prmO.Value = SMATERIAL;
            prmO.Direction = ParameterDirection.Input;
            lstParametros.Add(prmO);

            DbParameter prmP = new SqlParameter();
            prmP.DbType = DbType.String;
            prmP.ParameterName = "@SALTO";
            prmP.Value = SALTO;
            prmP.Direction = ParameterDirection.Input;
            lstParametros.Add(prmP);

            DbParameter prmQ = new SqlParameter();
            prmQ.DbType = DbType.String;
            prmQ.ParameterName = "@SLARGO";
            prmQ.Value = SLARGO;
            prmQ.Direction = ParameterDirection.Input;
            lstParametros.Add(prmQ);

            DbParameter prmR = new SqlParameter();
            prmR.DbType = DbType.String;
            prmR.ParameterName = "@SANCHO";
            prmR.Value = SANCHO;
            prmR.Direction = ParameterDirection.Input;
            lstParametros.Add(prmR);


            DbParameter prmS = new SqlParameter();
            prmS.DbType = DbType.Int32;
            prmS.ParameterName = "@IDIAMETRO";
            prmS.Value = IDIAMETRO;
            prmS.Direction = ParameterDirection.Input;
            lstParametros.Add(prmS);

            DbParameter prmT = new SqlParameter();
            prmT.DbType = DbType.Int32;
            prmT.ParameterName = "@INUMERODEDIVICIONES";
            prmT.Value = INUMERODEDIVICIONES;
            prmT.Direction = ParameterDirection.Input;
            lstParametros.Add(prmT);

            DbParameter prmU = new SqlParameter();
            prmU.DbType = DbType.String;
            prmU.ParameterName = "@STIPOASIGNACION";
            prmU.Value = STIPOASIGNACION;
            prmU.Direction = ParameterDirection.Input;
            lstParametros.Add(prmU);

            DbParameter prmV = new SqlParameter();
            prmV.DbType = DbType.String;
            prmV.ParameterName = "@STIPODEALTA";
            prmV.Value = STIPODEALTA;
            prmV.Direction = ParameterDirection.Input;
            lstParametros.Add(prmV);

            DbParameter prmW = new SqlParameter();
            prmW.DbType = DbType.Int32;
            prmW.ParameterName = "@INUMEROCOMPROBANTE";
            prmW.Value = INUMEROCOMPROBANTE;
            prmW.Direction = ParameterDirection.Input;
            lstParametros.Add(prmW);

            DbParameter prmX = new SqlParameter();
            prmX.DbType = DbType.String;
            prmX.ParameterName = "@SREPORTADOALSEGURO";
            prmX.Value = SREPORTADOALSEGURO;
            prmX.Direction = ParameterDirection.Input;
            lstParametros.Add(prmX);


            DbParameter prm1 = new SqlParameter();
            prm1.DbType = DbType.Double;
            prm1.ParameterName = "@IVALOR";
            prm1.Value = IVALOR;
            prm1.Direction = ParameterDirection.Input;
            lstParametros.Add(prm1);

            DbParameter prm2 = new SqlParameter();
            prm2.DbType = DbType.Int32;
            prm2.ParameterName = "@ICONCURRENCIA";
            prm2.Value = 1;
            prm2.Direction = ParameterDirection.Input;
            lstParametros.Add(prm2);

            DbParameter prm3 = new SqlParameter();
            prm3.DbType = DbType.Int32;
            prm3.ParameterName = "@LFAMILIAS_ID";
            prm3.Value = LFAMILIAS_ID;
            prm3.Direction = ParameterDirection.Input;
            lstParametros.Add(prm3);

            DbParameter prm4 = new SqlParameter();
            prm4.DbType = DbType.Int32;
            prm4.ParameterName = "@LPROVEEDOR_ID";
            prm4.Value = LPROVEEDOR_ID;
            prm4.Direction = ParameterDirection.Input;
            lstParametros.Add(prm4);

            DbParameter prm6 = new SqlParameter();
            prm6.DbType = DbType.Int32;
            prm6.ParameterName = "@LPERSONAL_ID";
            prm6.Value = LPERSONAL_ID;
            prm6.Direction = ParameterDirection.Input;
            lstParametros.Add(prm6);

            DbParameter prm61 = new SqlParameter();
            prm61.DbType = DbType.Int32;
            prm61.ParameterName = "@iEvento";
            prm61.Value = 1;
            prm61.Direction = ParameterDirection.Input;
            lstParametros.Add(prm61);


            SQLConexion conProxy = new SQLConexion();
            if (conProxy.EjecutarDML(lstParametros, "dbo.SPABM_ACTIVO"))
                return Convert.ToInt32(prmA.Value);
            return -1;

        }

        public bool Actualizar(int LACTIVOS_ID, string ICODIGOBARRAS, string SDESCIPCION_DSC, string SPROPIEDAD, DateTime DTFECHADECOMPRA_DT, DateTime DTFECHADEALTA_DT, int IVIDAUTIL, string SESTADO, string SMARCA, string SMODELO, string SFORMA, string SSERIAL, string SCOLOR, string SCAPACIDAD, string SMATERIAL, string SALTO, string SLARGO, string SANCHO, int IDIAMETRO, int INUMERODEDIVICIONES, string STIPOASIGNACION, string STIPODEALTA, int INUMEROCOMPROBANTE, string SREPORTADOALSEGURO, DateTime DTFECHABAJA, string SMOTIVOBAJA, double IVALOR, int ICONCURRENCIA, int LFAMILIAS_ID, int LPROVEEDOR_ID, int LPUNTOS_ID, int LPERSONAL_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();

            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LACTIVOS_ID";
            prmA.Value = LACTIVOS_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);

            DbParameter prmB = new SqlParameter();
            prmB.DbType = DbType.String;
            prmB.ParameterName = "@ICODIGOBARRAS";
            prmB.Value = ICODIGOBARRAS;
            prmB.Direction = ParameterDirection.Input;
            lstParametros.Add(prmB);

            DbParameter prmC = new SqlParameter();
            prmC.DbType = DbType.String;
            prmC.ParameterName = "@SDESCIPCION_DSC";
            prmC.Value = SDESCIPCION_DSC;
            prmC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmC);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.String;
            prmD.ParameterName = "@SPROPIEDAD";
            prmD.Value = SPROPIEDAD;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);

            DbParameter prmE = new SqlParameter();
            prmE.DbType = DbType.DateTime;
            prmE.ParameterName = "@DTFECHADECOMPRA_DT";
            prmE.Value = DTFECHADECOMPRA_DT;
            prmE.Direction = ParameterDirection.Input;
            lstParametros.Add(prmE);

            DbParameter prmF = new SqlParameter();
            prmF.DbType = DbType.DateTime;
            prmF.ParameterName = "@DTFECHADEALTA_DT";
            prmF.Value = DTFECHADEALTA_DT;
            prmF.Direction = ParameterDirection.Input;
            lstParametros.Add(prmF);

            DbParameter prmG = new SqlParameter();
            prmG.DbType = DbType.Int32;
            prmG.ParameterName = "@IVIDAUTIL";
            prmG.Value = IVIDAUTIL;
            prmG.Direction = ParameterDirection.Input;
            lstParametros.Add(prmG);

            DbParameter prmH = new SqlParameter();
            prmH.DbType = DbType.String;
            prmH.ParameterName = "@SESTADO ";
            prmH.Value = SESTADO;
            prmH.Direction = ParameterDirection.Input;
            lstParametros.Add(prmH);

            DbParameter prmI = new SqlParameter();
            prmI.DbType = DbType.String;
            prmI.ParameterName = "@SMARCA";
            prmI.Value = SMARCA;
            prmI.Direction = ParameterDirection.Input;
            lstParametros.Add(prmI);

            DbParameter prmJ = new SqlParameter();
            prmJ.DbType = DbType.String;
            prmJ.ParameterName = "@SMODELO ";
            prmJ.Value = SMODELO;
            prmJ.Direction = ParameterDirection.Input;
            lstParametros.Add(prmJ);

            DbParameter prmK = new SqlParameter();
            prmK.DbType = DbType.String;
            prmK.ParameterName = "@SFORMA";
            prmK.Value = SFORMA;
            prmK.Direction = ParameterDirection.Input;
            lstParametros.Add(prmK);

            DbParameter prmL = new SqlParameter();
            prmL.DbType = DbType.String;
            prmL.ParameterName = "@SSERIAL";
            prmL.Value = SSERIAL;
            prmL.Direction = ParameterDirection.Input;
            lstParametros.Add(prmL);

            DbParameter prmM = new SqlParameter();
            prmM.DbType = DbType.String;
            prmM.ParameterName = "@SCOLOR";
            prmM.Value = SCOLOR;
            prmM.Direction = ParameterDirection.Input;
            lstParametros.Add(prmM);

            DbParameter prmN = new SqlParameter();
            prmN.DbType = DbType.String;
            prmN.ParameterName = "@SCAPACIDAD";
            prmN.Value = SCAPACIDAD;
            prmN.Direction = ParameterDirection.Input;
            lstParametros.Add(prmN);

            DbParameter prmO = new SqlParameter();
            prmO.DbType = DbType.String;
            prmO.ParameterName = "@SMATERIAL";
            prmO.Value = SMATERIAL;
            prmO.Direction = ParameterDirection.Input;
            lstParametros.Add(prmO);

            DbParameter prmP = new SqlParameter();
            prmP.DbType = DbType.String;
            prmP.ParameterName = "@SALTO";
            prmP.Value = SALTO;
            prmP.Direction = ParameterDirection.Input;
            lstParametros.Add(prmP);

            DbParameter prmQ = new SqlParameter();
            prmQ.DbType = DbType.String;
            prmQ.ParameterName = "@SLARGO";
            prmQ.Value = SLARGO;
            prmQ.Direction = ParameterDirection.Input;
            lstParametros.Add(prmQ);

            DbParameter prmR = new SqlParameter();
            prmR.DbType = DbType.String;
            prmR.ParameterName = "@SANCHO";
            prmR.Value = SANCHO;
            prmR.Direction = ParameterDirection.Input;
            lstParametros.Add(prmR);


            DbParameter prmS = new SqlParameter();
            prmS.DbType = DbType.Int32;
            prmS.ParameterName = "@IDIAMETRO ";
            prmS.Value = IDIAMETRO;
            prmS.Direction = ParameterDirection.Input;
            lstParametros.Add(prmS);

            DbParameter prmT = new SqlParameter();
            prmT.DbType = DbType.Int32;
            prmT.ParameterName = "@INUMERODEDIVICIONES";
            prmT.Value = INUMERODEDIVICIONES;
            prmT.Direction = ParameterDirection.Input;
            lstParametros.Add(prmT);

            DbParameter prmU = new SqlParameter();
            prmU.DbType = DbType.String;
            prmU.ParameterName = "@STIPOASIGNACION ";
            prmU.Value = STIPOASIGNACION;
            prmU.Direction = ParameterDirection.Input;
            lstParametros.Add(prmU);

            DbParameter prmV = new SqlParameter();
            prmV.DbType = DbType.String;
            prmV.ParameterName = "@STIPODEALTA";
            prmV.Value = STIPODEALTA;
            prmV.Direction = ParameterDirection.Input;
            lstParametros.Add(prmV);

            DbParameter prmW = new SqlParameter();
            prmW.DbType = DbType.Int32;
            prmW.ParameterName = "@INUMEROCOMPROBANTE";
            prmW.Value = INUMEROCOMPROBANTE;
            prmW.Direction = ParameterDirection.Input;
            lstParametros.Add(prmW);

            DbParameter prmX = new SqlParameter();
            prmX.DbType = DbType.String;
            prmX.ParameterName = "@SREPORTADOALSEGURO ";
            prmX.Value = SREPORTADOALSEGURO;
            prmX.Direction = ParameterDirection.Input;
            lstParametros.Add(prmX);


            DbParameter prmY = new SqlParameter();
            prmY.DbType = DbType.DateTime;
            prmY.ParameterName = "@DTFECHABAJA  ";
            prmY.Value = DTFECHABAJA;
            prmY.Direction = ParameterDirection.Input;
            lstParametros.Add(prmY);

            DbParameter prmZ = new SqlParameter();
            prmZ.DbType = DbType.DateTime;
            prmZ.ParameterName = "@SMOTIVOBAJA   ";
            prmZ.Value = SMOTIVOBAJA;
            prmZ.Direction = ParameterDirection.Input;
            lstParametros.Add(prmZ);


            DbParameter prm1 = new SqlParameter();
            prm1.DbType = DbType.Double;
            prm1.ParameterName = "@IVALOR";
            prm1.Value = IVALOR;
            prm1.Direction = ParameterDirection.Input;
            lstParametros.Add(prm1);

            DbParameter prm2 = new SqlParameter();
            prm2.DbType = DbType.Int32;
            prm2.ParameterName = "@ICONCURRENCIA ";
            prm2.Value = ICONCURRENCIA;
            prm2.Direction = ParameterDirection.Input;
            lstParametros.Add(prm2);

            DbParameter prm3 = new SqlParameter();
            prm3.DbType = DbType.Int32;
            prm3.ParameterName = "@LFAMILIAS_ID ";
            prm3.Value = LFAMILIAS_ID;
            prm3.Direction = ParameterDirection.Input;
            lstParametros.Add(prm3);

            DbParameter prm4 = new SqlParameter();
            prm4.DbType = DbType.Int32;
            prm4.ParameterName = "@LPROVEEDOR_ID";
            prm4.Value = LPROVEEDOR_ID;
            prm4.Direction = ParameterDirection.Input;
            lstParametros.Add(prm4);


            DbParameter prm5 = new SqlParameter();
            prm5.DbType = DbType.Int32;
            prm5.ParameterName = "@LPUNTOS_ID";
            prm5.Value = LPUNTOS_ID;
            prm5.Direction = ParameterDirection.Input;
            lstParametros.Add(prm5);


            DbParameter prm6 = new SqlParameter();
            prm6.DbType = DbType.Int32;
            prm6.ParameterName = "@LPERSONAL_ID ";
            prm6.Value = LPERSONAL_ID;
            prm6.Direction = ParameterDirection.Input;
            lstParametros.Add(prm6);

            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarDML(lstParametros, "dbo.SPABM_ACTIVO");
        }

        public bool Eliminar(int LACTIVOS_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();

            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LACTIVOS_ID";
            prmA.Value = LACTIVOS_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);

            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarDML(lstParametros, "dbo.SPABM_ACTIVO");
        }

        public DataSet TraerACTIVO()
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento";
            prmD.Value = 4;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_ACTIVO");
        }

        public DataSet TraerACTIVOXId(int LACTIVOS_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LACTIVOS_ID";
            prmA.Value = LACTIVOS_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);
            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento";
            prmD.Value = 5;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_ACTIVO");
        }
        public DataSet TraerUltimoCreado()
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento";
            prmD.Value = 8;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_ACTIVO");
        }
        public DataSet TraerACTIVOXCODIGOBARRA(string ICODIGOBARRAS)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.String;
            prmA.ParameterName = "@ICODIGOBARRAS ";
            prmA.Value = ICODIGOBARRAS;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);
            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento";
            prmD.Value = 7;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_ACTIVO");
        }


    }
}
